import { CellRenderer } from "../../../../fl/controls/listClasses/CellRenderer";
import { ObjCreate } from "../common/ObjCreate";
import { ImagesConst } from "../../resource/ImagesConst";
import { GTextFormat } from "../../../common/GTextFormat";
import { ColorConfig } from "../../resource/ColorConfig";
import { BaseItem } from "../common/BaseItem";
import { Language } from "../../../../extend/language/Language";
import { TOpenRechargeGiftBag } from "../../../../Message/Db/Tables/TOpenRechargeGiftBag";
import { Log } from "../../../../com/gengine/debug/Log";
import { ItemData } from "../../resource/info/ItemData";
import { OpenRechargeGiftBagConfig } from "../../resource/OpenRechargeGiftBagConfig";
import { Cache } from "../../cache/Cache";
import { ConsumeCountData } from "./ConsumeCountData";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { ConsumeDayData } from "./ConsumeDayData";
import { MergeRechargeData } from "./MergeRechargeData";
import { ScaleBitmap } from "../../../../com/mui/display/ScaleBitmap";
import { GButton } from "../../../../com/mui/controls/GButton";
//class ConsumeCountRenderder
    
    export  class ConsumeCountRenderder extends CellRenderer
    {
        constructor()
        {
            super();
            return;
        }

        protected /* override */ configUI(): void
        {
            super.configUI();
            this.initStyle();
            this._bg = ObjCreate.createBg(2, 2, 117, 150, this, ImagesConst.RechargeBottom);
            var loc1=new GTextFormat("", 12, 16776960, null, null, null, null, null, flash.text.TextFormatAlign.CENTER);
            this._numTxt = ObjCreate.createTextField("", 0, 5, 117, 20, this, loc1);
            var loc2=new GTextFormat("", 12, ColorConfig.instance.getItemColor(4).intColor, true, null, null, null, null, flash.text.TextFormatAlign.CENTER);
            this._nameBg = ObjCreate.createBg(0, 25, 117, 20, this, ImagesConst.FightingStrgBg);
            this._nameTxt = ObjCreate.createTextField("", 0, 25, 117, 20, this, loc2);
            this._itemBg = ObjCreate.createBg(27, 50, 64, 64, this, ImagesConst.PackItemBg);
            this._baseItem = new BaseItem();
            this._baseItem.move(29, 52);
            this._baseItem.setSize(60, 60);
            this._baseItem.isDragAble = false;
            this._baseItem.isDropAble = false;
            addChild(this._baseItem);
            this._getBtn = ObjCreate.createGButton(Language.getString(20146), 33, 120, 50, 25, this, "ButtonRed");
            this._getBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onGetBtnClickHandler);
            this._getBtn.enabled = false;
            this._getBtn.drawNow();
            return;
        }

        protected initStyle(): void
        {
            this.setStyle("downSkin", new Object /* flash.display.Bitmap */());
            this.setStyle("overSkin", new Object /* flash.display.Bitmap */());
            this.setStyle("upSkin", new Object /* flash.display.Bitmap */());
            this.setStyle("selectedDownSkin", new Object /* flash.display.Bitmap */());
            this.setStyle("selectedOverSkin", new Object /* flash.display.Bitmap */());
            this.setStyle("selectedUpSkin", new Object /* flash.display.Bitmap */());
            return;
        }

        public /* override */ set data(arg1: Object)
        {
            var loc1=null;
            var loc2=null;
            var loc3=0;
            super.data = arg1;
            if (arg1 && arg1 is TOpenRechargeGiftBag) 
            {
                if (this._getBtn == null) 
                {
                    Log.error("_getBtn null");
                }
                this._getBtn.enabled = false;
                this._giftBag = arg1 as TOpenRechargeGiftBag;
                loc1 = new ItemData(this._giftBag.itemCode);
                if (this._giftBag.itemCode == 0) 
                {
                    Log.error("_giftBag.itemCode 0 _giftBag", this._giftBag.code);
                }
                if (loc1 == null) 
                {
                    Log.error("itemData null");
                }
                if (this._nameTxt == null) 
                {
                    Log.error("_nameTxt null");
                }
                if (this._baseItem == null) 
                {
                    Log.error("_baseItem null");
                }
                if (this._numTxt == null) 
                {
                    Log.error("_numTxt null");
                }
                loc2 = ColorConfig.instance.getItemColorString(loc1.itemInfo.item.color);
                if (loc2 == null) 
                {
                    Log.error("color null");
                }
                this._nameTxt.htmlText = "<font color=\'" + loc2 + "\'>" + loc1.itemInfo.item.name + "</font>";
                this._baseItem.itemData = loc1;
                loc3 = OpenRechargeGiftBagConfig.instance.getGiftBagIndex(this._giftBag);
                this._numTxt.htmlText = Language.getString(35846) + loc3;
                if (this._giftBag.activetype == 1 || this._giftBag.activetype == 2 || this._giftBag.activetype == 4) 
                {
                    if (Cache.instance.role.consumeCount >= this._giftBag.target && !ConsumeCountData.isHadGet(this._giftBag.code)) 
                    {
                        this._getBtn.enabled = true;
                        this._getBtn.label = Language.getString(20146);
                        Dispatcher.dispatchEvent(new DataEvent(EventName.ConsumeIsGetGift, this._giftBag.activetype));
                    }
                    else 
                    {
                        if (ConsumeCountData.isHadGet(this._giftBag.code)) 
                        {
                            this._getBtn.label = Language.getString(20152);
                        }
                        else 
                        {
                            this._getBtn.label = Language.getString(20146);
                        }
                        this._getBtn.enabled = false;
                    }
                }
                else if (this._giftBag.activetype != 3) 
                {
                    if (this._giftBag.activetype == 5 || this._giftBag.activetype == 6) 
                    {
                        if (Cache.instance.role.consumeDay >= this._giftBag.target && !ConsumeDayData.isHadGet(this._giftBag.code)) 
                        {
                            this._getBtn.enabled = true;
                            this._getBtn.label = Language.getString(20146);
                            Dispatcher.dispatchEvent(new DataEvent(EventName.ConsumeIsGetGift, this._giftBag.activetype));
                        }
                        else 
                        {
                            if (ConsumeDayData.isHadGet(this._giftBag.code)) 
                            {
                                this._getBtn.label = Language.getString(20152);
                            }
                            else 
                            {
                                this._getBtn.label = Language.getString(20146);
                            }
                            this._getBtn.enabled = false;
                        }
                    }
                }
                else if (Cache.instance.role.mergeRecharge >= this._giftBag.target && !MergeRechargeData.isHadGet(this._giftBag.code)) 
                {
                    this._getBtn.enabled = true;
                    this._getBtn.label = Language.getString(20146);
                }
                else 
                {
                    if (MergeRechargeData.isHadGet(this._giftBag.code)) 
                    {
                        this._getBtn.label = Language.getString(20152);
                    }
                    else 
                    {
                        this._getBtn.label = Language.getString(20146);
                    }
                    this._getBtn.enabled = false;
                }
                this._getBtn.drawNow();
            }
            return;
        }

        public /* override */ set selected(arg1: Boolean)
        {
            super.selected = arg1;
            if (this._gradientGlow == null) 
            {
                this._gradientGlow = new Object /* flash.filters.GradientGlowFilter */();
                this._gradientGlow.distance = 0;
                this._gradientGlow.angle = 45;
                this._gradientGlow.colors = [16777062, 16776960];
                this._gradientGlow.alphas = [0, 1];
                this._gradientGlow.ratios = [0, 255];
                this._gradientGlow.blurX = 5;
                this._gradientGlow.blurY = 5;
                this._gradientGlow.strength = 2;
                this._gradientGlow.quality = flash.filters.BitmapFilterQuality.HIGH;
                this._gradientGlow.type = flash.filters.BitmapFilterType.OUTER;
            }
            if (arg1) 
            {
                this._bg.filters = [this._gradientGlow];
                if (this._giftBag && (this._giftBag.activetype == 1 || this._giftBag.activetype == 2 || this._giftBag.activetype == 4)) 
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.ConsumeCountItemSelected, this._giftBag));
                }
                else if (this._giftBag && this._giftBag.activetype == 3) 
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.MergeRechargeItemSelected, this._giftBag));
                }
                else if (this._giftBag && (this._giftBag.activetype == 5 || this._giftBag.activetype == 6)) 
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.ConsumeDayItemSelected, this._giftBag));
                }
                mouseChildren = true;
            }
            else 
            {
                this._bg.filters = [];
            }
            return;
        }

        /* internal  */onGetBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._giftBag) 
            {
                if (this._giftBag.activetype == 1 || this._giftBag.activetype == 2 || this._giftBag.activetype == 4) 
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.ConsumeCountGetGiftBag, this._giftBag.code));
                }
                else if (this._giftBag.activetype != 3) 
                {
                    if (this._giftBag.activetype == 5 || this._giftBag.activetype == 6) 
                    {
                        Dispatcher.dispatchEvent(new DataEvent(EventName.ConsumeDayGetGiftBag, this._giftBag.code));
                    }
                }
                else 
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.MergeRechargeGiftBagGet, this._giftBag.code));
                }
            }
            return;
        }

        /* internal */ /* var */_bg: ScaleBitmap;

        /* internal */ /* var */_numTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_nameTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_baseItem: BaseItem;

        /* internal */ /* var */_getBtn: GButton;

        /* internal */ /* var */_nameBg: ScaleBitmap;

        /* internal */ /* var */_itemBg: ScaleBitmap;

        /* internal */ /* var */_giftBag: TOpenRechargeGiftBag;

        /* internal */ /* var */_gradientGlow: Object /* flash.filters.GradientGlowFilter */;
    }
